package cn.edu.njtc.controller;

import cn.edu.njtc.common.R;
import cn.edu.njtc.entity.dto.ActivityCreateDto;
import cn.edu.njtc.entity.dto.ActivityQueryDto;
import cn.edu.njtc.entity.dto.ActivityUpdateDto;
import cn.edu.njtc.entity.pojo.EducationActivity;
import cn.edu.njtc.exception.BizException;
import cn.edu.njtc.service.EducationActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@Tag(name = "患教活动管理接口")
@RequestMapping("/education-activities")
@RequiredArgsConstructor
public class EducationActivityController {
    private final EducationActivityService activityService;
    @Operation(summary = "获取患教活动列表")
    @GetMapping
    public R<List<EducationActivity>> listActivities() {
        return R.ok(activityService.listActivities());
    }
    @Operation(summary = "id获取单个患教活动详情")
    @GetMapping("/{activityId}")
    public R<EducationActivity> getActivity(@PathVariable Long activityId) {
        return R.ok(activityService.getActivityById(activityId));
    }
    @Operation(summary = "创建患教活动")
    @PostMapping
    public R<Long> createActivity(@RequestBody @Valid ActivityCreateDto createDTO) {
        return R.ok(activityService.createActivity(createDTO));
    }
    @Operation(summary = "更新患教活动")
    @PutMapping
    public R<Void> updateActivity(@RequestBody @Valid ActivityUpdateDto updateDto) throws BizException {
        activityService.updateActivity(updateDto);
        return R.ok("更新活动成功");
    }
    @Operation(summary = "取消患教活动")
    @PostMapping("/{activityId}/cancel")
    public R<Void> cancelActivity(@PathVariable Long activityId,
                                  @RequestParam String cancelReason) throws BizException {
        activityService.cancelActivity(activityId, cancelReason);
        return R.ok("取消活动成功");
    }
    @Operation(summary = "获取患教活动状态选项")
    @GetMapping("/status-options")
    public R<List<String>> getStatusOptions() {
        return R.ok(Arrays.asList("未开始", "进行中", "已结束", "已取消"));
    }
}